window.addEventListener('DOMContentLoaded', () => {
  const { contextBridge, ipcRenderer } = require('electron');

  // 暴露给渲染进程的API
  // sendMessageToMain | message-to-main | response-from-main
  // getLog | message-get-log | response-get-log
  contextBridge.exposeInMainWorld('electronAPI', {
    sendMessageToMain: (message, callback) => {
      ipcRenderer.send('message-to-main', message);
      ipcRenderer.on('response-from-main', (event, response) => {
        callback(response);
      });
    },
    getLog: (message, callback) => {
      ipcRenderer.send('message-get-log', message);
      ipcRenderer.on('response-get-log', (event, response) => {
        callback(response);
      });
    },
    getJobList: (message, callback) => {
      ipcRenderer.send('message-get-job-list', message);
      ipcRenderer.on('response-get-job-list', (event, response) => {
        callback(response);
      });
    },
    getJobDescription: (message, callback) => {
      ipcRenderer.send('message-get-job-description', message);
      ipcRenderer.on('response-get-job-description', (event, response) => {
        callback(response);
      });
    },
    deleteJobList: (message, callback) => {
      ipcRenderer.send('message-delete-job-list', message);
      ipcRenderer.on('response-delete-job-list', (event, response) => {
        callback(response);
      });
    },
    updateJobStatus: (message, callback) => {
      ipcRenderer.send('message-update-job-status', message);
      ipcRenderer.on('response-update-job-status', (event, response) => {
        callback(response);
      });
    },
    updateSubmitStatus: (message, callback) => {
      ipcRenderer.send('message-update-submit-status', message);
      ipcRenderer.on('response-update-submit-status', (event, response) => {
        callback(response);
      });
    },

    updateJobCategory: (message, callback) => {
      ipcRenderer.send('message-update-job-category', message);
      ipcRenderer.on('response-update-job-category', (event, response) => {
        callback(response);
      });
    },

    fetchCollectData: (message, callback) => {
      ipcRenderer.send('message-get-collect-data', message);
      ipcRenderer.on('response-get-collect-data', (event, response) => {
        callback(response);
      });
    },

    runCollectData: (message, callback) => {
      ipcRenderer.send('message-run-collect-rule', message);
      ipcRenderer.on('response-run-collect-rule', (event, response) => {
        callback(response);
      });
    },

  })

})